package image.utils;

import image.processing.ImageProcessor;
import image.processing.ImageProcessor.CompressAlgorithm;

import java.awt.image.BufferedImage;

public class Degrade {
	public static BufferedImage generateDegrade(int height, int width) {
		BufferedImage ans = new BufferedImage(width, height,
				BufferedImage.TYPE_BYTE_GRAY);
		int values[][] = new int[ans.getWidth()][ans.getHeight()];
		double currentDegradeValue = 0;
		for (int x = 0; x < ans.getHeight(); x++) {
			for (int y = 0; y < ans.getWidth(); y++) {
				values[y][x] = (int) Math.floor(currentDegradeValue);
				currentDegradeValue += ((double) width) / 255;
			}
		}

		ans = ImageProcessor.generateCompressedImage1Channel(values,
				CompressAlgorithm.LINEAR);

		return ans;
	}

	public static BufferedImage generateDegrade(int height, int width, int R,
			int G, int B) {

	/*	BufferedImage img = new BufferedImage(width, height,
				BufferedImage.TYPE_3BYTE_BGR);
		int intValues0[][] = new int[img.getWidth()][img.getHeight()];
		int intValues1[][] = new int[img.getWidth()][img.getHeight()];
		int intValues2[][] = new int[img.getWidth()][img.getHeight()];
		double currentDegradeValue0 = R;
		double currentDegradeValue1 = G;
		double currentDegradeValue2 = B;
		double min0 = Integer.MIN_VALUE;
		double min1 = Integer.MIN_VALUE;
		double min2 = Integer.MIN_VALUE;
		
			for (int y = 0; y < img.getHeight(); y++) {
				currentDegradeValue0 -= ((double) width) / 255;
				currentDegradeValue1 -= ((double) width) / 255;
				currentDegradeValue2 -= ((double) width) / 255;
			}
		
		min0 = currentDegradeValue0;
		min1 = currentDegradeValue1;
		min2 = currentDegradeValue2;

		 currentDegradeValue0 = R;
		 currentDegradeValue1 = G;
		 currentDegradeValue2 = B;
		
		for (int x = 0; x < img.getHeight(); x++) {
			for (int y = 0; y < img.getWidth(); y++) {
				intValues0[y][x] = (int) Math.floor(currentDegradeValue0);
				intValues1[y][x] = (int) Math.floor(currentDegradeValue1);
				intValues2[y][x] = (int) Math.floor(currentDegradeValue2);
				currentDegradeValue0 += ((double) width) / 255 + min0;
				currentDegradeValue1 += ((double) width) / 255 + min1;
				currentDegradeValue2 += ((double) width) / 255 + min2;
			}
		}

		return ImageProcessor.generateCompressedImage3Channel(intValues0,
				intValues1, intValues2, CompressAlgorithm.LINEAR);*/
		return null;
	}
}
